﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using Database;
using Business;
using System.Web.UI.WebControls;
using System.Globalization;

namespace DT5_Anh09110006_Hung09110044_Vu09110157.QuanLy
{
    public partial class SuaHocVien : System.Web.UI.Page
    {
        protected string GiaTriNgaySinh { get; set; }
        Business.QuanLyHocVien qlhocvien = new Business.QuanLyHocVien();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["MaHocVien"] != null)
                {
                    loaddulieu();
                }
                else
                {
                    Response.Redirect("QuanLyHocVien.aspx");
                }
            }

        }
        private void loaddulieu()
        {
            String mahocvien = Session["MaHocVien"].ToString();
            HocVien hv =qlhocvien.LayHocVienTheoMa(mahocvien);
            txtMaHV.Text=hv.MaHV;
            txtHoTenHV.Text=hv.HoTenHV;
            txtDiaChiHV.Text=hv.DiaChi;
            this.GiaTriNgaySinh = hv.NgaySinh.Value.ToString("MM/dd/yyyy");
            ddlGioiTinhHV.SelectedValue=hv.GioiTinh;
            txtDienThoaiHV.Text=hv.DienThoai;   
            txtCMNDHV.Text=hv.CMND;
            txtEmailHV.Text = hv.Email;
        }
        protected void btnSuaHV_Click(object sender, EventArgs e)
        {
            Session["MaHocVien"] = null;
            HocVien hv = new HocVien
            {
                MaHV = txtMaHV.Text,
                HoTenHV = txtHoTenHV.Text,
                DiaChi = txtDiaChiHV.Text,
                NgaySinh = System.DateTime.ParseExact(Request["txtNgaysinh"], "MM/dd/yyyy", CultureInfo.InvariantCulture),
                GioiTinh = ddlGioiTinhHV.SelectedValue,
                DienThoai = txtDienThoaiHV.Text,              
                CMND = txtCMNDHV.Text,
                Email = txtEmailHV.Text
              
            };
            if (qlhocvien.SuaHocVien(hv))
            {

                Response.Write("<script language='javascript' type='text/javascript'>"
                                 + " alert('Chỉnh sửa thành công');"
                                 + "window.location='QuanLyHocVien.aspx'"
                                 + "</script>");
              
            }
            else
            {
                Response.Write("<script language='javascript' type='text/javascript'>"
                             + "alert('Không thể chỉnh sửa học viên này');"
                             + "window.location='QuanLyLopHoc.aspx'"
                             + "</script>");
            }
            
           

        }

        protected void btnHuy_Click(object sender, EventArgs e)
        {
            Session["MaHocVien"] = null;
            Response.Redirect("QuanLyHocVien.aspx");
        }
    }
}